package com.px.user.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.px.user.model.ActionModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.math.BigDecimal;
import java.sql.Timestamp;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity(name = "reward_his")
@ApiModel(value = "打赏礼物记录对象", description = "打赏礼物记录字段")
@org.hibernate.annotations.Table(appliesTo = "reward_his", comment = "打赏礼物记录表")
public class RewardHis {
    @Id
    @ApiModelProperty(value = "主键", hidden = true)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Null(groups = {ActionModel.Insert.class}, message = "删除id字段")
    @Column(unique = true, nullable = false, columnDefinition = "bigint comment '主键'")
    private Long id;

    @NotNull(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "礼物ID", example = "1")
    @Column(columnDefinition = "bigint comment '礼物ID'")
    private Long rewardId;

    @NotNull(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "房间ID", example = "1")
    @Column(columnDefinition = "bigint comment '房间ID'")
    private Long roomId;

    @Null(groups = {ActionModel.Insert.class}, message = "删除fromUserId字段")
    @Column(columnDefinition = "bigint comment '发送人ID'")
    @ApiModelProperty(value = "发送人ID", example = "1")
    private Long fromUserId;

    @Null(groups = {ActionModel.Insert.class}, message = "删除money字段")
    @Column(columnDefinition = "decimal(12,2) comment '礼物金额'")
    @ApiModelProperty(value = "礼物金额", example = "10.9", hidden = true)
    private BigDecimal money;

    @NotNull(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "接收人ID", example = "2")
    @Column(columnDefinition = "bigint comment '接收人ID'")
    private Long toUserId;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "创建时间", hidden = true)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间'", insertable = false, updatable = false)
    private Timestamp createTime;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "更新时间", hidden = true)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间'", insertable = false, updatable = false)
    private Timestamp updateTime;

    /**
     * 扩展字段
     */
    @Transient
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty(value = "发送人昵称", hidden = true)
    private String fromNickname;

    @Transient
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty(value = "接收人昵称", hidden = true)
    private String toNickname;

    /**
     * 扩展查询字段
     */
    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询开始时间", hidden = true)
    private Timestamp qstart;

    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询结束时间", hidden = true)
    private Timestamp qend;

    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询排序字段", hidden = true)
    private String orderField;

    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询开始索引", hidden = true)
    private Integer startIndex;

    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询返回数量", hidden = true)
    private Integer limit;
}
